package text;

import java.io.*;
import java.util.ArrayList;

public class listtext {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ArrayList<Person> list = new ArrayList<>();
        list.add(new Person("王狗蛋",18));
        list.add(new Person("李狗子",20));
        list.add(new Person("刘二腿",54));
        //先搞一搞list存放Person
        FileOutputStream fos = new FileOutputStream("C:\\Users\\啦啦啦\\Desktop\\e.txt",true);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        //将集合放入oos中
        oos.writeObject(list);
        /*=========================================*/
        //查看保存的对象
        FileInputStream fis = new FileInputStream("C:\\Users\\啦啦啦\\Desktop\\e.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object o = ois.readObject();
        ArrayList<Person> listcopy = (ArrayList<Person>)o;
        //将o强制转化为ArrayList类型
        System.out.println(list);
        System.out.println("===============");
        System.out.println(listcopy);
        ois.close();
        oos.close();
    }
}
